package com.maotouying.owlextremeapp.activity;

import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.google.gson.Gson;
import com.maotouying.owlextremeapp.R;
import com.maotouying.owlextremeapp.api.Api;
import com.maotouying.owlextremeapp.api.ApiConfig;
import com.maotouying.owlextremeapp.api.TitleCallback;
import com.maotouying.owlextremeapp.utils.StringUtils;

import java.util.HashMap;

public class RegisterActivity extends BaseActivity {

    private EditText etAccount;
    private EditText etPwd;
    private Button btnRegister;



    @Override
    protected int initLayout() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {
        etAccount = findViewById(R.id.et_account);
        etPwd = findViewById(R.id.et_pwd);
        btnRegister = findViewById(R.id.btn_register);
    }

    @Override
    protected void initDate() {
        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String account = etAccount.getText().toString().trim();
                String pwd = etPwd.getText().toString().trim();
                register(account,pwd);
            }
        });
    }

    private void register(String account, String pwd) {
        if (StringUtils.isEmpty(account)) {
            showToast("没有输入账号，请输入账号吧");
            return;
        }
        if (StringUtils.isEmpty(pwd)) {
            showToast("还没输入密码，输入一下密码哦");
            return;
        }

        // Map params = new HashMap();
        HashMap<String, Object> params = new HashMap<>();
        params.put("mobile", account);
        params.put("password", pwd);
        Api.config(ApiConfig.REGISTER,params).postRequest(new TitleCallback() {
            @Override
            public void onSuccess(final String res) {
                Log.e("onSuccess", res);
                Gson gson = new Gson();
                showToastSync("注册成功");

            }

            @Override
            public void onFailure(Exception e) {
                Log.e("onFailure", e.toString());
            }
        });

    }
}